﻿using System;
using System.Collections.Generic;
using System.Reflection;
using Sirenix.OdinInspector;


namespace Gp.Scripts.Data.Equip {
    [Serializable]
    public class WeaponPhrase {
        [ValueDropdown("PhraseList")]
        [InfoBox("@InfoBox()")]
        public string phrase = "";

        public WeaponPhraseDecorator ToDecorator => WeaponPhraseMapper.Map(phrase);

        public string GetInfo() {
            var type = WeaponPhraseMapper.MapType(phrase);
            if (type == null) {
                return "暂无信息";
            }

            var attribute = type.GetCustomAttribute<WeaponPhraseAttribute>();
            return attribute == null ? "暂无信息" : attribute.Info;
        }


#if UNITY_EDITOR
        private WeaponPhraseAttribute _attribute;
        
        private IEnumerable<string> PhraseList => WeaponPhraseMapper.DecoratorsNames;

        private string InfoBox() {
            var type = WeaponPhraseMapper.MapType(phrase);
            if (type == null) {
                return "None ...";
            }
            _attribute = type.GetCustomAttribute<WeaponPhraseAttribute>();
            return _attribute == null ? "None ..." : _attribute.Info;
        }
#endif
    }
}